package iPod;

import java.io.IOException;
import java.io.RandomAccessFile;

public class TrackItem extends IDBChunk
{
	// Data values stored
	private int rating = 0;
	private int numParams = 0;
	private int fileSize = 0;
	private String location = "";
	private String title = "";
	private String artist = "";
	private String album = "";
	
	public TrackItem()
	{
		expectedID = "mhit";
	}
	
	public void readChild(IDBChunk chunk, RandomAccessFile in) throws Exception
    {
		if (chunk.typeID.equalsIgnoreCase("mhod"))
		{
			DataObject param = new DataObject();
			param.load(in);
			
			switch(param.getDataType())
			{
			case DataObject.TITLE:
				title = param.getStringValue();
				break;
			case DataObject.LOCATION:
				location = param.getStringValue();
				break;
			case DataObject.ARTIST:
				artist = param.getStringValue();
				break;
			case DataObject.ALBUM:
				album = param.getStringValue();
				break;
			}			
		}
		else
		{
			super.readChild(chunk, in);
		}
    }
	
	public void loadHeader(RandomAccessFile in) throws Exception
    { 
		super.loadHeader(in);
		
		// Load extra database information:
		// read the number of describing strings
		in.read(item);
		numParams = DataUtils.littleEndianToInt(item);
		
		// read the rating of this track
		in.seek(startPos + 31);
		rating = in.read();
		
		// read the size of the file
		in.seek(startPos + 36);
		in.read(item);
		fileSize = DataUtils.littleEndianToInt(item);
    }

	public int getRating() {
		return rating;
	}

	public int getFileSize() {
		return fileSize;
	}

	public String getLocation() {
		return location;
	}

	public String getTitle() {
		return title;
	}

	public String getArtist() {
		return artist;
	}

	public String getAlbum() {
		return album;
	}
	
	public void setRating(int rating) {
		this.rating = rating;
	}

}

